//
//  XDLMInvestTwoTableViewCell.m
//  xindailianmeng
//
//  Created by 许佳奇 on 17/2/9.
//  Copyright © 2017年 xindailianmeng.cn. All rights reserved.
//

#import "XDLMInvestTwoTableViewCell.h"
#define KSCREENW3 kScreenW/3
@implementation XDLMInvestTwoTableViewCell
{
    UILabel *_percentLab;//进度百分数
    UILabel *_nameLab;//产品名字
    UILabel *_monthLab;//月份
    UILabel *_LeftInvestLab;//剩余可投金额
    UIImage *_leftImg;
}
- (void)awakeFromNib {
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUI];
    }
    return self;
}
- (void)setUI
{
    _percentLab = [self createLabelWithFrame:CGRectMake(0, 4*kscale, kScreenW/3, 80*kscale) text:@"4.80%" textFont:[UIFont systemFontOfSize:22] textColor:[UIColor redColor]];
    _percentLab.textAlignment = NSTextAlignmentCenter;
    _percentLab.attributedText = [self changeLabelWithText:_percentLab.text];
    [self addSubview:_percentLab];
    
    UIView *middleView = [[UIView alloc] initWithFrame:CGRectMake(kScreenW/3, 0, kScreenW/3, 90*kscale)];
    [self addSubview:middleView];
    _nameLab = [self createLabelWithFrame:CGRectMake(25*kscale, 16*kscale, KSCREENW3, 16*kscale) text:@"资金周转" textFont:[UIFont systemFontOfSize:12] textColor:[UIColor grayColor]];
    [middleView addSubview:_nameLab];
    _monthLab = [self createLabelWithFrame:CGRectMake(25*kscale, 36, KSCREENW3, 20*kscale) text:@"3个月" textFont:[UIFont systemFontOfSize:18] textColor:[UIColor redColor]];
    [middleView addSubview:_monthLab];
    _LeftInvestLab = [self createLabelWithFrame:CGRectMake(25*kscale, 60, KSCREENW3, 15*kscale) text:@"剩余可投20万" textFont:[UIFont systemFontOfSize:12] textColor:[UIColor grayColor]];
    [middleView addSubview:_LeftInvestLab];
    _leftImg = [UIImage imageNamed:@"qiang"];
    UIImageView *leftImgView = [[UIImageView alloc] initWithImage:_leftImg];
    leftImgView.frame = CGRectMake(kScreenW-81*kscale-15, 31*kscale, 81*kscale, 25*kscale);
    [self addSubview:leftImgView];
}
#pragma mark ---辅助放方法
//改变Label.Text后几位字符串大小
-(NSMutableAttributedString*) changeLabelWithText:(NSString*)needText
{
    
    NSMutableAttributedString *strAttribute = [[NSMutableAttributedString alloc] initWithString:needText];
    [strAttribute addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:28] range:NSMakeRange(0, 1)];
    return strAttribute;
}

- (UILabel *)createLabelWithFrame:(CGRect)frame text:(NSString *)text textFont:(UIFont *)font textColor:(UIColor *)color {
    
    UILabel * label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.textColor = color;
    label.font = font;
    label.adjustsFontSizeToFitWidth = YES;
//    label.textAlignment = NSTextAlignmentCenter;
    
    return label;
    
}
-(void)setModel:(XDLMInvestModel *)model
{
    _percentLab.text = [NSString stringWithFormat:@"%.2f%%",[model.rate floatValue]/100];
    _percentLab.attributedText = [self changeLabelWithText:_percentLab.text];
    _nameLab.text = model.name;
    _monthLab.text = model.postTimeLimit;
    if ([model.remainMoney integerValue] < 10000) {
        _LeftInvestLab.text = [NSString stringWithFormat:@"剩余可投%.2f元",[model.remainMoney floatValue]];
    }
    else
    {
        _LeftInvestLab.text = [NSString stringWithFormat:@"剩余可投%.2f万元",[model.remainMoney floatValue]/10000];
    }
    if ([model.status isEqualToString:@"0"]) {
        
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
